/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ik.Reposteria.SMP.Ventanas;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.ParseException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.ik.Reposteria.SMP.Ventanas.Modelos.TableModelDirecciones;
import org.ik.Reposteria.SMP.Encapsulados.Direcciones;
import org.ik.Reposteria.SMP.Encapsulados.DireccionesPK;
import org.ik.Reposteria.SMP.Encapsulados.Direcciones_Tabla;
import org.ik.Reposteria.SMP.Encapsulados.Usuarios;
import org.ik.Reposteria.SMP.Manejadores.ManejadorClientes;
import org.ik.Reposteria.SMP.Manejadores.ManejadorDirecciones;
import org.ik.Reposteria.SMP.Manejadores.ManejadorPedidos;

/**
 *
 * @author Malkavian
 */
public class Pedidos extends javax.swing.JFrame {

    Usuarios u = new Usuarios();
    org.ik.Reposteria.SMP.Encapsulados.Clientes cliente = new org.ik.Reposteria.SMP.Encapsulados.Clientes();
    org.ik.Reposteria.SMP.Encapsulados.Direcciones direccion = new Direcciones();
    org.ik.Reposteria.SMP.Encapsulados.DireccionesPK direccion_pk = new DireccionesPK();
    List<Direcciones_Tabla> direcciones_tabla = new ArrayList<Direcciones_Tabla>();
    List<Direcciones> direcciones = new ArrayList<Direcciones>();

    
    public Pedidos(Usuarios u) {

        this.u = u;

        initComponents();

//        tabla_detalles.setModel(new TableModelDirecciones());

        Dimension d = new Dimension(this.getSize());
        Dimension g = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(g.width / 2 - d.width / 2, g.height / 2 - d.height / 2, d.width, d.height);

        setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        texto_telefono = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        texto_nombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        texto_apellido = new javax.swing.JTextField();
        boton_busqueda_cliente = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla_detalles = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        boton_agregar_producto = new javax.swing.JButton();
        boton_limpiar_producto = new javax.swing.JButton();
        boton_borrar_detalle = new javax.swing.JButton();
        boton_busqueda_producto = new javax.swing.JButton();
        texto_idproducto = new javax.swing.JTextField();
        texto_total = new javax.swing.JTextField();
        texto_total_itbis = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        texto_total_totales = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        boton_guardar_pedido = new javax.swing.JButton();
        boton_borrar_pedido = new javax.swing.JButton();
        boton_limpiar_pedido = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        texto_no_pedido = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        texto_fecha_pedido = new javax.swing.JTextField();
        boton_busqueda_pedido = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        textarea_comentario = new javax.swing.JTextArea();
        jLabel11 = new javax.swing.JLabel();
        texto_no_pedido1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        boton_busqueda_pedido1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        boton_busqueda_imagen = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();

        jTextField1.setText("jTextField1");

        jTextField4.setText("jTextField4");

        jTextField2.setText("jTextField2");

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("SMP - Información Pedidos");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Teléfono:");

        try {
            texto_telefono.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###-###-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        texto_telefono.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        texto_telefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                texto_telefonoKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setText("Nombre:");

        texto_nombre.setEditable(false);
        texto_nombre.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Apellido:");

        texto_apellido.setEditable(false);
        texto_apellido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        boton_busqueda_cliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/group.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(boton_busqueda_cliente, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(texto_apellido)
                    .addComponent(texto_telefono)
                    .addComponent(texto_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(boton_busqueda_cliente)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel2)
                        .addComponent(texto_telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(texto_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(texto_apellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detalles Pedido", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        tabla_detalles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabla_detalles.setEnabled(false);
        tabla_detalles.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabla_detallesMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tabla_detalles);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("Productos:");

        boton_agregar_producto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_agregar_producto.setText("Agregar a Detalle");
        boton_agregar_producto.setEnabled(false);
        boton_agregar_producto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton_agregar_productoActionPerformed(evt);
            }
        });

        boton_limpiar_producto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_limpiar_producto.setText("Limpiar");
        boton_limpiar_producto.setEnabled(false);
        boton_limpiar_producto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton_limpiar_productoActionPerformed(evt);
            }
        });

        boton_borrar_detalle.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_borrar_detalle.setText("Borrar Detalles");
        boton_borrar_detalle.setEnabled(false);

        boton_busqueda_producto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/cake.png"))); // NOI18N
        boton_busqueda_producto.setEnabled(false);

        texto_idproducto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        texto_total.setEditable(false);
        texto_total.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        texto_total_itbis.setEditable(false);
        texto_total_itbis.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Totales:");

        texto_total_totales.setEditable(false);
        texto_total_totales.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/cake_23.png"))); // NOI18N

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/cake_choko.png"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(boton_busqueda_producto, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(texto_idproducto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boton_agregar_producto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boton_limpiar_producto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boton_borrar_detalle))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jLabel8)
                        .addGap(44, 44, 44)
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(texto_total_itbis, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(texto_total, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(texto_total_totales, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(boton_busqueda_producto)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(texto_idproducto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(boton_agregar_producto)
                        .addComponent(boton_limpiar_producto)
                        .addComponent(boton_borrar_detalle)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(jLabel8)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(texto_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(texto_total_itbis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(texto_total_totales, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(38, 38, 38))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        boton_guardar_pedido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_guardar_pedido.setText("Guardar Pedido");
        boton_guardar_pedido.setEnabled(false);
        boton_guardar_pedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton_guardar_pedidoActionPerformed(evt);
            }
        });

        boton_borrar_pedido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_borrar_pedido.setText("Borrar Pedido");
        boton_borrar_pedido.setEnabled(false);

        boton_limpiar_pedido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_limpiar_pedido.setText("Limpiar Pantalla");
        boton_limpiar_pedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boton_limpiar_pedidoActionPerformed(evt);
            }
        });

        jButton6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton6.setText("Cerrar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(boton_guardar_pedido)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(boton_limpiar_pedido)
                .addGap(18, 18, 18)
                .addComponent(boton_borrar_pedido)
                .addGap(18, 18, 18)
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(boton_guardar_pedido)
                    .addComponent(boton_limpiar_pedido)
                    .addComponent(boton_borrar_pedido)
                    .addComponent(jButton6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información Pedidos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("No. Pedido:");

        texto_no_pedido.setEditable(false);
        texto_no_pedido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Fecha:");

        texto_fecha_pedido.setEditable(false);
        texto_fecha_pedido.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        boton_busqueda_pedido.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/find.png"))); // NOI18N
        boton_busqueda_pedido.setEnabled(false);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel10.setText("Comentaio:");

        textarea_comentario.setEditable(false);
        textarea_comentario.setColumns(20);
        textarea_comentario.setRows(5);
        jScrollPane2.setViewportView(textarea_comentario);

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel11.setText("Estado:");

        texto_no_pedido1.setEditable(false);
        texto_no_pedido1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel13.setText("Dirección:");

        boton_busqueda_pedido1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/find.png"))); // NOI18N
        boton_busqueda_pedido1.setEnabled(false);

        jComboBox1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        boton_busqueda_imagen.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        boton_busqueda_imagen.setText("Imagen de Referencia");

        jTextField3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel11))
                                .addGap(28, 28, 28)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(texto_fecha_pedido, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(boton_busqueda_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(texto_no_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(boton_busqueda_pedido1, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(texto_no_pedido1))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(boton_busqueda_imagen)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(jLabel6)
                                .addComponent(texto_no_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(boton_busqueda_pedido))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(texto_fecha_pedido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel13)
                        .addComponent(texto_no_pedido1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(boton_busqueda_pedido1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(boton_busqueda_imagen)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/ik/Reposteria/SMP/Recursos/posted.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(55, 55, 55)
                                .addComponent(jLabel12))
                            .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void boton_agregar_productoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boton_agregar_productoActionPerformed
    }//GEN-LAST:event_boton_agregar_productoActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        Principal p = new Principal(u);
        dispose();
    }//GEN-LAST:event_jButton6ActionPerformed

    private void boton_limpiar_productoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boton_limpiar_productoActionPerformed
        texto_idproducto.setText("");
    }//GEN-LAST:event_boton_limpiar_productoActionPerformed

    private void boton_limpiar_pedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boton_limpiar_pedidoActionPerformed
        texto_telefono.setText("");
        texto_nombre.setText("");
        texto_apellido.setText("");

        texto_apellido.setEnabled(true);
        texto_nombre.setEnabled(true);
        boton_agregar_producto.setEnabled(true);
        boton_borrar_pedido.setEnabled(true);
        boton_guardar_pedido.setEnabled(true);
        boton_limpiar_producto.setEnabled(true);
        boton_borrar_detalle.setEnabled(true);
        tabla_detalles.setEnabled(true);
    }//GEN-LAST:event_boton_limpiar_pedidoActionPerformed

    private void texto_telefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_texto_telefonoKeyTyped
        if (evt.getKeyChar() == '\n') {

            if (texto_telefono.getText().toCharArray().length == 12) {

                cliente = ManejadorClientes.getInstance().getClientePorTelefono(texto_telefono.getText());

                if (cliente != null) {

                    texto_nombre.setText(cliente.getNombre().trim());
                    texto_apellido.setText(cliente.getApellido().trim());

//                    direcciones = ManejadorDirecciones.getInstance().getDireccionesCliente(texto_telefono.getText());
//
//                    if (direcciones_tabla != null) {
//                        for (int i = 0; i < direcciones_tabla.size(); i++) {
//                            direcciones_tabla.remove(i);
//                        }
//                    }
//
//                    for (Direcciones d : direcciones) {
//                        Direcciones_Tabla dt = new Direcciones_Tabla();
//
//                        dt.setTelefono(d.getDireccionesPK().getClientesTelefono());
//                        dt.setIddireccion(d.getDireccionesPK().getIddireccion());
//                        dt.setDireccion(d.getDireccion());
//                        direcciones_tabla.add(dt);
//
//                    }

//                    tabla_detalles.setModel(new TableModelDirecciones(direcciones_tabla));

                    texto_apellido.setEnabled(true);
                    texto_nombre.setEnabled(true);
                    boton_agregar_producto.setEnabled(true);
                    boton_borrar_pedido.setEnabled(true);
                    boton_guardar_pedido.setEnabled(true);
                    boton_limpiar_producto.setEnabled(true);
                    boton_borrar_detalle.setEnabled(true);
                    boton_busqueda_pedido.setEnabled(true);
                    boton_busqueda_producto.setEnabled(true);
                    tabla_detalles.setEnabled(true);
                    texto_no_pedido.setEditable(true);
                    textarea_comentario.setEditable(true);

                    int max = ManejadorPedidos.getInstance().maxPedidosPorCliente(cliente.getTelefono());

                    if (max == 0) {
                        texto_no_pedido.setText("1");
                        texto_no_pedido.setEditable(false);
                        boton_busqueda_pedido.setEnabled(false);
                        
                    } else {
                      max++;
                      texto_no_pedido.setText(""+max);
                    }


                } else {
                    JOptionPane.showMessageDialog(null, "Teléfono no existe.", "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(null, "Teléfono no existe.", "Error", JOptionPane.ERROR_MESSAGE);
            }

        }
    }//GEN-LAST:event_texto_telefonoKeyTyped

    private void tabla_detallesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabla_detallesMouseClicked
    }//GEN-LAST:event_tabla_detallesMouseClicked

    private void boton_guardar_pedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boton_guardar_pedidoActionPerformed

        if (texto_apellido.getText().isEmpty() || texto_nombre.getText().isEmpty() || texto_telefono.getText().isEmpty()) {
            JOptionPane.showMessageDialog(null, "Favor llenar todas las informaciones.", "Error", JOptionPane.ERROR_MESSAGE);
        } else {
        }


    }//GEN-LAST:event_boton_guardar_pedidoActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boton_agregar_producto;
    private javax.swing.JButton boton_borrar_detalle;
    private javax.swing.JButton boton_borrar_pedido;
    private javax.swing.JButton boton_busqueda_cliente;
    private javax.swing.JButton boton_busqueda_imagen;
    private javax.swing.JButton boton_busqueda_pedido;
    private javax.swing.JButton boton_busqueda_pedido1;
    private javax.swing.JButton boton_busqueda_producto;
    private javax.swing.JButton boton_guardar_pedido;
    private javax.swing.JButton boton_limpiar_pedido;
    private javax.swing.JButton boton_limpiar_producto;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTable tabla_detalles;
    private javax.swing.JTextArea textarea_comentario;
    private javax.swing.JTextField texto_apellido;
    private javax.swing.JTextField texto_fecha_pedido;
    private javax.swing.JTextField texto_idproducto;
    private javax.swing.JTextField texto_no_pedido;
    private javax.swing.JTextField texto_no_pedido1;
    private javax.swing.JTextField texto_nombre;
    private javax.swing.JFormattedTextField texto_telefono;
    private javax.swing.JTextField texto_total;
    private javax.swing.JTextField texto_total_itbis;
    private javax.swing.JTextField texto_total_totales;
    // End of variables declaration//GEN-END:variables
   

}
